﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Main
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void AglinLeftBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.AlignLeft();
        }

        private void AglinBottomBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.AlignBottom();
        }

        private void AglinTopBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.AlignTop();
        }

        private void AglinRightBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.AlignRight();
        }

        private void VerticalLayoutBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.VertialLayout();
        }

        private void HorizontalLayoutBtn_Click(object sender, RoutedEventArgs e)
        {
            //cav.HorizontalLayout();
        }
        private bool isDragging = false;
        private Point startPosition;
        private double startLeft;
        private double startTop;
        private void dragRectangle_MouseDown(object sender, MouseButtonEventArgs e)
        {
            isDragging = true;
            startPosition = e.GetPosition(cav);
            startLeft = Canvas.GetLeft(dragRectangle);
            startTop = Canvas.GetTop(dragRectangle);
            dragRectangle.CaptureMouse();
        }

        private void dragRectangle_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                double offsetX = e.GetPosition(cav).X - startPosition.X;
                double offsetY = e.GetPosition(cav).Y - startPosition.Y;
                Canvas.SetLeft(dragRectangle, startLeft + offsetX);
                Canvas.SetTop(dragRectangle, startTop + offsetY);
            }
        }

        private void dragRectangle_MouseUp(object sender, MouseButtonEventArgs e)
        {
            isDragging = false;
            dragRectangle.ReleaseMouseCapture();

            // 保存控件位置
            double left = Canvas.GetLeft(dragRectangle);
            double top = Canvas.GetTop(dragRectangle);
            SavePosition(left, top);
        }

        private void SavePosition(double left, double top)
        {
            // TODO: 将位置保存到某个数据持久化方式（如数据库、文件、配置文件等）
        }
    }

}
